const app = getApp();
const http = require('../../../utils/util.js');
const mta = require('../../../mta_sdk/mta_analysis.js');
Page({

  data: {
    baseImg: '',
    bgpic: '',
    stuSchool: '',
    stuClass: '',
    stuName: '',
    stuPic: '',
    lastImg: '',
    avaWidth: 200,
    avaHeight: 200,
    pid:''
  },
  onShow() {
    var cover = wx.getStorageSync('coverpic')
    if (cover || cover != '') {
      this.setData({
        lastImg: cover || '',
        stuPic: cover || ''
      })
    }
  },
  onLoad: function (opt) {
    mta.Page.init();
    console.log(opt);
    if (opt.pid) {
      this.setData({
        baseImg: `/images/${opt.pid}_list.jpg`,
        pid: opt.pid
      })
    }

  },
  formSubmit: function (e) {
    app.sendForm(e);
  },
  getStuPic: function (e) {
    var me = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        var tempFilePaths = res.tempFilePaths;
        wx.navigateTo({
          url: `/pages/cropperview/cropperview?pic=${tempFilePaths}&w=${me.data.avaWidth}&h=${me.data.avaHeight}`
        })
      }
    })
  },
  toShowImg() {
    var md = this.data;

    if (md.stuPic == '') {
      this.tip("请上传图片")
    }
    else {
      wx.navigateTo({
        url: `/pages/${md.pid}/${md.pid}_detail/${md.pid}_detail?pic=${md.stuPic}&pid=${md.pid}`,
      })
    }

  },
  tip(txt) {
    wx.showToast({
      title: txt,
      icon: 'none'
    });
  },
  onUnload() {
    wx.removeStorageSync("coverpic")
  },
  onShareAppMessage: function () {
    return {
      title: '红领巾制作',
      desc: '红领巾制作',
      path: `/pages/index/index`,

    }
  }
})